package greedy;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 435. 无重叠区间
 * User: Li_yizYa
 * Date: 2025/6/27
 * Time: 9:22
 */
public class Solution13 {
    public int eraseOverlapIntervals(int[][] intervals) {
        if (intervals == null || intervals.length == 0) {
            return -1;
        }
        Arrays.sort(intervals, (a, b) -> {
            return a[0] - b[0];
        });
        int ret = 0;
        int min = intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            if (min > intervals[i][0]) {
                ret++;
                min = Math.min(min, intervals[i][i]);
            } else {
                min = intervals[i][1];
            }
        }
        return ret;
    }
}
